/**
 * Created by Adi on 16/8/15.
 */
"use strict";

import React from 'react';
import {
	View,
	Text,
	StyleSheet,
	Navigator,
	BackAndroid,
	Platform,
	DeviceEventEmitter,
	AppState,
	ErrorUtils
} from 'react-native';

import Main from './view/Main';

export const STATUS_BAR_HEIGHT = (Platform.OS === 'ios' ? 30 : 25);

var _navigator;

class App extends React.Component {

	constructor(props, context, update) {
		super(props, context, update);
	}

	renderScene(route, navigator) {

		console.info(`app renderScene '${route.name}'`);

		let Component = route.component;
		_navigator = navigator;
		// 注册成全局
		global.appNavigator || (global.appNavigator = navigator);

		return (
			<Component
				navigator={navigator}
				{...route}
				route={route}
				showActivityIndicator={this.showActivityIndicator}
				hideActivityIndicator={this.hideActivityIndicator}
			/>
		);
		// var props = Object.assign({}, { navigator: navigator }, route.passProps);
		// return React.createElement(route.components, props);
	}

	// 配置场景动画和手势
	configureScene(route, routeStack) {
		if (route.sceneConfig) { // 有设置场景
			return route.sceneConfig;
		}

		return Navigator.SceneConfigs.PushFromRight;
	}

	getInitialRoute() {
		return {
			name: 'Splash',
			component: Main,
			title: 'XXXXXXXx',
			member: {
				id:1,
				name: 'name'
			},
			myStyle: styles.page
		};
	}

	render() {
		return (
			<Navigator
				ref='navigator'
				style={styles.flex}
				configureScene={this.configureScene}
				renderScene={this.renderScene}
				initialRoute={this.getInitialRoute()}
			/>
		);
	}
}

const styles = StyleSheet.create({
	flex: {
		flex: 1
	},
	statusBar: {
		height: STATUS_BAR_HEIGHT
	},

	page: {
		paddingTop: 48,
		backgroundColor: '#f00',
	}
});


export default App;
